<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
[#include "/admin/include/head.htm"]
<script type="text/javascript">
	var grid;
	$(function(){
		 grid = $("#maingrid").ligerGrid({
            columns: [
                {hide: true, name: 'path'},
				{display: 'ID', name: 'id', width:50, align: 'center', isAllowHide: false},
				{display: '商品名称', name: 'name', align: 'center', width: 200 ,render:function(row){
					return "<a target='_blank' style='color:blue' href='"+row["path"]+"'>"+row["name"]+"</a>";
				}},
				{display: '商品编码', name: 'code', align: 'center', width: 100 },
				{display: '商品分类', name: 'goodsCategory.name', align: 'center', width: 120 },
				{display: '规格', name: 'spec', align: 'center', width: 100 },
				{display: '库存', name: 'stock', align: 'center', width: 100},
				{display: '销售价', name: 'marketPrice', align: 'center', width: 80},
                {display: '转化比率', name: 'integralRate', align: 'center', width: 80},
				{display: '是否上架', name: 'isMarketable', align: 'center', width: 100, 
					render: function(row){
						return row.isMarketable == "true" ? '是' : '否';
					}
				}
			],  pageSize:20, url: 'queryData.jhtml',toolbar: {}, width: '100%', height:'100%', enabledSort: true
        });
		
        $("#pageloading").hide();
		LG.loadToolbar(grid);
		//绑定搜索按钮
		LG.search(grid);
		
		$("#goodsCategoryIsNull").change(function(){
			var val = $.trim($(this).val());
			if(val == ""){
				$(this).attr("name","");
			}else if(val == "isNull"){
				$(this).attr("name","search_isNull_goodsCategory");
			}else if(val == "isNotNull"){
				$(this).attr("name","search_isNotNull_goodsCategory");
			}
		});
	});
	
	function add(){
		top.f_addTab(null, '新增商品', 'b2c/goods/add.jhtml?parentMenuNo=goods_list');
	}
	
	function f_delete() {
		var selecteds = grid.getSelecteds();
	    if (selecteds.length > 0) {
	    	jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
      			if (confirm){
					LG.ajax({
						url: base + '/admin/b2c/goods/delete.jhtml',
			            loading: '正在删除中...',
			            data: { ids: LG.getIds(selecteds) },
			            success: function () {
							LG.showSuccess('删除成功');
			                f_reload();
			            },
			            error: function (message) {
							LG.showError(message);
			            }
			        });
			    }
			});
		} else {
			LG.tip('请选择行!');
	    }
	}
	
	/**
	 * 商品上架
	 */
	function upMarket() {
		var selecteds = grid.getSelecteds();
	    if (selecteds.length > 0) {
	    	jQuery.ligerDialog.confirm('确定上架吗?', function (confirm) {
      			if (confirm){
					LG.ajax({
						url: base + '/admin/b2c/goods/upMarket.jhtml',
			            loading: '正在上架中...',
			            data: { ids: LG.getIds(selecteds) },
			            success: function () {
							LG.showSuccess('操作成功!');
			                f_reload();
			            },
			            error: function (message) {
							LG.showError(message);
			            }
			        });
			    }
			});
		} else {
			LG.tip('请选择行!');
	    }
	}
	  
	/**
	 * 商品下架
	 */
	function downMarket() {
		var selecteds = grid.getSelecteds();
	    if (selecteds.length > 0) {
	    	jQuery.ligerDialog.confirm('确定下架吗?', function (confirm) {
      			if (confirm){
					LG.ajax({
						url: base + '/admin/b2c/goods/downMarket.jhtml',
			            loading: '正在下架中...',
			            data: { ids: LG.getIds(selecteds) },
			            success: function () {
							LG.showSuccess('操作成功!');
			                f_reload();
			            },
			            error: function (message) {
							LG.showError(message);
			            }
			        });
			    }
			});
		} else {
			LG.tip('请选择行!');
	    }
	}  
	  
	//编辑商品
	function edit(){
		var selecteds = grid.getSelecteds();
		if (selecteds.length != 1) { 
			LG.tip('请选择一行记录!'); 
			return; 
		}
		top.f_addTab(null, '修改商品', 'b2c/goods/edit.jhtml?id=' + selecteds[0].id);
	};
	
	
	function uploadPic() {
		var selected = grid.getSelected();
		if (!selected) { 
			LG.tip('请选择行!'); 
			return; 
		}
		top.f_addTab(null, '商品图片上传', 'b2c/goods/uploadPic.jhtml?id=' + selected.id);
	}
</script>
</head>
<body style="padding:10px; overflow:hidden;">
	<div id="functions">
		<div class="clearfix">
			<div style="float:left;">
				<span>
					商品名称：<input type="text" class="formText" name="search_LIKE_name"/>
				</span>
				<span>
					商品编码：<input type="text" class="formText" name="search_LIKE_code"/>
				</span>
				<span>
					商品分类：<input type="text" class="formText" name="search_LIKE_goodsCategory.name"/>
				</span>
				<span>
					条形码：<input type="text" class="formText" name="search_LIKE_barcode"/>
				</span>
				<span>
					商品分类是否为空：[@u.select headerKey="" headerValue="全部"
				headerButtom="false" list={"isNull":"是","isNotNull":"否"}
				name="search_isNotNull_goodsCategory" id="goodsCategoryIsNull"/]
				</span>
				<input type="button" class="button" value="搜索" id="search"/>
				<a href="#" id="search_btn_reset" face="Wingdings 3">清除本次搜索</a>
			</div>
		</div>
	</div>
	<div id="maingrid" style="margin:0; padding:0"></div>
</body>
</html>